<?php
declare (strict_types = 1);

namespace app\middleware;
use think\facade\Db;
class Auth
{


    private  $accesstoken                 = '';
    private $default_method         = 'json';
    /**
     * 处理请求
     * 验证签名
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        return $next($request);
        $request->debug = $request->param('debug');
        if($request->debug == 2 || $request->debug == 1){
            $request->tokeninfo = [];
            return $next($request);
        }
        $headers = \Tools::get_all_header();
        if(isset($headers['accesstoken']) && empty($headers['accesstoken']) === FALSE) {
            $this->accesstoken = $headers['accesstoken'];
        }else{
            return \Tools::returnMsg(false,array(
                'message'   => '必传参数丢失',
                'code'      => '10005'
            ),$this->default_method);
        }
        $tokeninfo = \Tools::checkJWTToken($this->accesstoken);
        $request->tokeninfo = $tokeninfo;
        return $next($request);
    }
}
